<?php

namespace app\common;

use Yii;
use yii\web\Controller;
use yii\base\InlineAction;

class BaseController extends Controller
{
    /**
     * @param string $id    继承原方法实现驼峰命名
     * @return null|object|\yii\base\InlineAction
     * @throws \yii\base\InvalidConfigException
     */
	public function createAction($id)
    {
        if ($id === '') {
            $id = $this->defaultAction;
        }

        $actionMap = $this->actions();
        if (isset($actionMap[$id])) {
            return \Yii::createObject($actionMap[$id], [$id, $this]);
        } elseif (preg_match('/^[a-z0-9\\-_]+$/', $id) && strpos($id, '--') === false && trim($id, '-') === $id) {
            $methodName = 'action' . str_replace(' ', '', ucwords(implode(' ', explode('-', $id))));
            if (method_exists($this, $methodName)) {
                $method = new \ReflectionMethod($this, $methodName);
                if ($method->isPublic() && $method->getName() === $methodName) {
                    return new InlineAction($id, $this, $methodName);
                }
            }
        } else {
            $methodName = 'action' . $id;
            if (method_exists($this, $methodName)) {
                $method = new \ReflectionMethod($this, $methodName);
                if ($method->isPublic() && $method->getName() === $methodName) {
                    return new InlineAction($id, $this, $methodName);
                }
            }
        }

        return null;
    }

    /**
     * 自定义格式化打印函数
     */
    protected static function dd()
    {
        //$numargs = func_num_args();
        $args = func_get_args();
        echo "<pre/>";
        var_dump($args);
        die;
    }
}
